package com.kangfu.api.controller;

import cn.hutool.core.util.StrUtil;
import com.kangfu.api.interceptor.AuthorizationInterceptor;
import com.kangfu.api.service.IFeedbackService;
import com.kangfu.common.model.AjaxResult;
import com.kangfu.db.model.request.FeedbackRequest;
import com.kangfu.db.model.vo.FeedbackVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    @Autowired
    public IFeedbackService feedbackService;

    @PostMapping("/add")
    public AjaxResult add(@RequestAttribute(AuthorizationInterceptor.LOGIN_USER_ID) int userId, @RequestBody FeedbackRequest feedbackRequest) {
        feedbackService.insertFeedback(userId, feedbackRequest);

        return AjaxResult.success();
    }

    @GetMapping("/list")
    public AjaxResult list(@RequestAttribute(AuthorizationInterceptor.LOGIN_USER_ID) int userId, @RequestParam(name = "page", defaultValue = "1") int page) {
        List<FeedbackVo> list = feedbackService.selectFeedbackListByUserId(userId, page);
        return AjaxResult.success(list);
    }



}
